
 ////////////////////////////////////////////////////////////// Text generated at
 //     ___      _                         _   ____    ___   // http://www.network-science.de/ascii/
 //    / _ \___ | | _____  /\/\   ___   __| | |___ \  / _ \  // using ogre font.
 //   / /_)/ _ \| |/ / _ \/    \ / _ \ / _` |   __) || | | | //
 //  / ___/ (_) |   <  __/ /\/\ \ (_) | (_| |  / __/ | |_| | //
 // /_/    \___/|_|\_\___\/    \/\___/ \__,_| |_____(_)___/  //
 //                                                          //
 //////////////////////////////////////////////////////////////
          //                                        //
          //      The World of Pokemon Reborn.      //
          //                                        //
          ////////////////////////////////////////////

 /*
 *   ___ _                         _              
 *  / __| |_  __ _ _ _  __ _ ___  | |   ___  __ _ 
 * | (__| ' \/ _` | ' \/ _` / -_) | |__/ _ \/ _` |
 *  \___|_||_\__,_|_||_\__, \___| |____\___/\__, |
 *                     |___/                |___/ 
 *
 *	v2.0 - 2011/??/??
 *							- 
 *
 *	v1.0 - 2006/01/15
 *							- Released to the public: https://forums.alliedmods.net/showthread.php?t=23281
 *
 */





	///////////////////////////////////////////////////
	//        DO NOT CHANGE ANYTHING IN HERE!        //
	//      Things for customizing your server       //
	//        can be done from the admin menu        //
	///////////////////////////////////////////////////





 #if defined _pokemod_plugin_included
	#endinput
 #endif
 #define _pokemod_plugin_included

 //Uncomment to allow PokeMod to display debug messages (if they come up). Remember you must recompile if you change this.
 #define POKEMOD_DEBUG

 //Uncomment to allow PokeMod to display advanced debug messages. This might flood your server. Only use it if you are getting random crashes/infinite loops and need to find where they are happening. Remember you must recompile if you change this.
 //Check the logs folder for PM_YY_MM_DD_HH_MM.log
 #define POKEMOD_ADV_DEBUG

 //Uncomment to keep an advance debug file for every initial function call
 #define POKEMOD_ADV_DEBUG_MULT

 //By default, plugins have 4KB of stack space.
 //This gives the plugin a little more memory to work with (2* default = 8192, 3* default = 12288)
 #pragma dynamic 12288

 //Lets load some libraries
 #include <amxmodx>
 #include <amxmisc>
 #include <cstrike>
 #include <engine>
 #include <fakemeta_util>
 #include <fun>
 #include <hamsandwich>
 #include <nfvault>
 #include <xs>

 #if AMXX_VERSION_NUM < 180
	#assert _____\
			PokeMod requires AMXX 1.8 or higher and must be compiled locally!\
			_____
 #endif

 //Create fake tags
 #define Int: _:
 #define String: _:
 #define Coord: _:
 #define Vector: Float:


 #tryinclude "money_ul.inc"

 #include "pokemod/constants.inc"
 #include "pokemod/macros.inc"

 #include "pokemod/admin.h"
 #include "pokemod/damage.h"
 #include "pokemod/effects.h"
 #include "pokemod/encounter.h"
 #include "pokemod/entity.h"
 #include "pokemod/file.h"
 #include "pokemod/item.h"
 #include "pokemod/menu.h"
 #include "pokemod/player.h"
 #include "pokemod/pokemon.h"
 #include "pokemod/script.h"
 #include "pokemod/setting.h"
 #include "pokemod/setup.h"
 #include "pokemod/skill.h"
 #include "pokemod/status.h"
 #include "pokemod/stats.h"
 #include "pokemod/type.h"

 #include "pokemod/globals.inc"

 #include "pokemod/admin.inc"
 #include "pokemod/command.inc"
 #include "pokemod/core.inc"
 #include "pokemod/damage.inc"
 #include "pokemod/dhud.inc"
 #include "pokemod/effects.inc"
 #include "pokemod/encounter.inc"
 #include "pokemod/entity.inc"
 #include "pokemod/event.inc"
 #include "pokemod/file.inc"
 #include "pokemod/forward.inc"
 #include "pokemod/item.inc"
 #include "pokemod/level.inc"
 #include "pokemod/load.inc"
 #include "pokemod/location.inc"
 #include "pokemod/menu.inc"
 #include "pokemod/natives.inc"
 #include "pokemod/player.inc"
 #include "pokemod/pokemon.inc"
 #include "pokemod/save.inc"
 #include "pokemod/script.inc"
 #include "pokemod/setting.inc"
 #include "pokemod/setup.inc"
 #include "pokemod/skill.inc"
 #include "pokemod/stats.inc"
 #include "pokemod/status.inc"
 #include "pokemod/stocks.inc"
 #include "pokemod/trade.inc"
 #include "pokemod/type.inc"


 ///////////////////////////////////////
 //  Called to initialize the plugin  //
 ///////////////////////////////////////
 PM_FUNC_PUBLIC_ATTRIB plugin_init()
 {
	//Placing this here because this may be the first forward called
	pokemod_advdebug_file();

	pokemod_funcstart_debug( "plugin_init" );

	//Register the most important things first (PokeMod might be off)
	register_plugin( "PokeMod", g_szVersion, "Emp`" );
	set_pcvar_string( register_cvar( "PokeMod_Version", g_szVersion, FCVAR_SERVER|FCVAR_SPONLY ), g_szVersion );

	//Commands to show information and enable/disable PokeMod
	register_concmd( "pokemod", "CommandPokemod", ADMIN_ALL, "- information about PokeMod" );
	register_concmd( "pm", "CommandPokemod" );

	//Register Say Commands to interact with PokeMod
	//Also if PokeMod is off, we will tell people if they mention PokeMod
	register_clcmd( "say", "CommandSay" );

	//If PokeMod is off, we don't need to waste server resources
	if ( g_iState == PM_DISABLED )
	{
		log_amx( "PokeMod is Disabled" );

		//Register these commands, because when you alt-tab out of a game, in console it says invalid command
		register_clcmd( "-pokeskill", "CommandPokeskillUp" );
		register_clcmd( "-pokeitem", "CommandPokeitemUp" );

		pokemod_funcend_debug( "plugin_init Disabled" );

		return;
	}

	//Catch pointers of game cvars
	mp_friendlyfire = get_cvar_pointer( "mp_friendlyfire" );
	mp_logdetail = get_cvar_pointer( "mp_logdetail" );

	//Register Ham Events
	RegisterHam( Ham_TakeDamage, szEntityPlayer, "EventDamage" );
	RegisterHam( Ham_Spawn, szEntityPlayer, "EventRespawnPost", 1 );
//	RegisterHam( Ham_CS_RoundRespawn, szEntityPlayer, "EventRespawnPost", 1 );
	RegisterHam( Ham_Killed, szEntityPlayer, "EventKilled" );
	RegisterHam( Ham_Use, szEntityHostage, "EventHostageUse" );

	//Register Other Events
	register_logevent("EventRoundStart", 2, "1=Round_Start")
	register_event( "HLTV", "EventHLTV", "a", "1=0", "2=0" );
	register_logevent( "EventRoundEnd", 2, "1=Round_End" );
	register_logevent( "EventRoundEnd", 2, "1&Restart_Round_" );

	//Register the radio menus so we can show unused menus afterwards
	new Int:iMenuKeys = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<9);
	register_menucmd( register_menuid( "#RadioA", 1 ), iMenuKeys, "EventMenuClose" );
	register_menucmd( register_menuid( "#RadioB", 1 ), iMenuKeys, "EventMenuClose" );
	register_menucmd( register_menuid( "#RadioC", 1 ), iMenuKeys, "EventMenuClose" );

	//StatusValue is sent when a player looks at players/hostages
	register_event( "StatusValue", "EventStatusValue", "b", "1=2", "2!0" );

//	register_message( get_user_msgid( "Health" ), "MessageHealth" );

	register_event( "CurWeapon", "EventCurWeapon", "be", "1=1" );
	register_touch( szEntityPlayer, "*", "EventTouch" );

	//Register events for pokeskill entities
	register_think( szEntityPokeSkill, "EventSkillThink" );
	register_touch( szEntityPokeSkill, "*", "EventSkillTouch" );

	//Register the forward for the game description to change it to PokeMod
	register_forward( FM_GetGameDescription, "ForwardGetGameDescription" );

	//Create an entity that thinks every second
	g_iEntityLoop = EntityCreate();
	set_pev( g_iEntityLoop, pev_classname, "PokeModLoop" );
	register_think( "PokeModLoop", "EventLoop" );
	set_pev( g_iEntityLoop, pev_nextthink, get_gametime() + 1.0 );

	//Command to activate a pokeskill
	register_clcmd( "+pokeskill", "CommandPokeskillDown", _, "- uses pokemon bind skill" );
	register_clcmd( "-pokeskill", "CommandPokeskillUp" );

	//Commands to activate a specific pokeskill
	for ( new String:szCommand[32], Int:iSkillNum = 1; iSkillNum <= SKILLS_PER_POKEMON; iSkillNum++ )
	{
		formatex( szCommand, 31, "+pokeskill%d", iSkillNum );
		register_clcmd( szCommand, "CommandPokeskillDown" );
		szCommand[ 0 ] = '-';
		register_clcmd( szCommand, "CommandPokeskillUp" );
	}

	//Commands to use items and show pokemart
	register_clcmd( "+pokeitem", "CommandPokeitemDown", _, "- brings up Item Menu" );
	register_clcmd( "-pokeitem", "CommandPokeitemUp" );

	//Commands to see other players' information
//	register_concmd( "playerspokemon", "CommandPlayersPokemon", _, "- shows everyones pokemon" );		//views players pokemon
//	register_concmd( "playerspokes", "CommandPlayersPokemon" );											//views players pokemon
//	register_concmd( "playersskills", "CommandPlayersSkills", _, "- shows everyones skills" );			//views players skills
//	register_concmd( "playersitems", "CommandPlayersItems", _, "- shows everyones items" );				//views players items
//	register_concmd( "pokerank", "CommandPlayersRanks", _, "- shows players PokeRanks" );				//views players ranks

	//Commands to see pokemon and pokeitems
//	register_concmd( "pokedex", "CommandPokedex", _, "- shows pokemon information" );					//views pokedex
//	register_concmd( "pokeitem", "CommandPokeitem", _, "- shows pokeitem information" );				//views pokeitem help

	//Register admin commands
	AdminInit();

	//HL Messages that we are going to send to players
	g_msgScreenShake = get_user_msgid("ScreenShake");
	g_msgScreenFade = get_user_msgid("ScreenFade");
	g_msgScoreInfo = get_user_msgid("ScoreInfo");
	g_msgDeathMsg = get_user_msgid("DeathMsg");
	g_msgDamage = get_user_msgid("Damage");

	//MultiForwards for other plugins to interact with PokeMod
	g_iForwardUseItem = CreateMultiForward( "PokeModUseItem", ET_STOP, FP_CELL, FP_CELL, FP_STRING );

	//The HudSync used to show information to the player
	g_iHudSync = CreateHudSyncObj();
	g_iStatHudSync = CreateHudSyncObj();

	//Start PokeScript Functionality
	ScriptInit();

	//Read from files
	FileReadPokemon();
	FileReadItems();
	FileReadLocations();

	//Register skills
	SkillInit();

	pokemod_funcend_debug( "plugin_init" );
 }

 ////////////////////////////////////////////////////////////////////////////
 //  Called 1 second after plugin_init when config files have been loaded  //
 ////////////////////////////////////////////////////////////////////////////
 PM_FUNC_PUBLIC_ATTRIB plugin_cfg()
 {
	//If we successfully included money_ul.inc
	#if defined money_ul_included
		//Check if the plugin was loaded
		g_iPluginUnlimMoney = is_plugin_loaded( "Unlimited Money" );
	#endif
 }

 ///////////////////////////////////////////////
 //  Called to precache items for the plugin  //
 ///////////////////////////////////////////////
 PM_FUNC_PUBLIC_ATTRIB plugin_precache()
 {
	//Placing this here because this may be the first forward called
	pokemod_advdebug_file();

	pokemod_funcstart_debug( "plugin_precache" );

	//load the multilingual file for pokemod
//	register_dictionary( "pokemod.txt" );

	for ( new POKE_SOUNDS:iSound; iSound < POKE_SOUNDS; iSound++ )
		PokeModPrecacheSound( iSound );
	for ( new POKE_SPRITES:iSprite; iSprite < POKE_SPRITES; iSprite++ )
		PokeModPrecacheSprite( iSprite );
	for ( new POKE_MODELS:iModel; iModel < POKE_MODELS; iModel++ )
		PokeModPrecacheModel( iModel );
	for ( new POKE_MODELST:iModelT; iModelT < POKE_MODELST; iModelT++ )
		PokeModPrecacheModelT( iModelT );

	new Int:iMissingFiles = PokeModMissingFiles();
	if ( iMissingFiles )
	{
		log_amx( "The server is missing %d file%c", iMissingFiles, iMissingFiles == 1 ? EOS : 's' );
		g_iState = PM_DISABLED;
	}

	//Precache these for the Oak entity (fake hostage)
	engfunc( EngFunc_PrecacheSound, "hostage/hos1.wav" );
	engfunc( EngFunc_PrecacheSound, "hostage/hos2.wav" );
	engfunc( EngFunc_PrecacheSound, "hostage/hos3.wav" );
	engfunc( EngFunc_PrecacheSound, "hostage/hos4.wav" );
	engfunc( EngFunc_PrecacheSound, "hostage/hos5.wav" );

	pokemod_funcend_debug( "plugin_precache" );
 }
 PM_FUNC_NORM_ATTRIB PokeModPrecacheModel( const POKE_MODELS:iModel )
 {
	if ( file_exists( gModels[iModel] ) || contain( gModels[iModel], "pokemon" ) == -1 )
	{
		engfunc( EngFunc_PrecacheModel, gModels[iModel] );
		return ( g_bFoundModel[iModel] = true );
	}
	return false;
 }
 PM_FUNC_NORM_ATTRIB PokeModPrecacheModelT( const POKE_MODELST:iModelT )
 {
	if ( file_exists( gModelsT[iModelT] ) || contain( gModelsT[iModelT], "pokemon" ) == -1 )
	{
		engfunc( EngFunc_PrecacheModel, gModelsT[iModelT] );
		return ( g_bFoundModelT[iModelT] = true );
	}
	return false;
 }
 PM_FUNC_NORM_ATTRIB PokeModPrecacheSprite( const POKE_SPRITES:iSprite )
 {
	if ( file_exists( gSprites[iSprite] ) || contain( gSprites[iSprite], "pokemon" ) == -1 )
	{
		SPRITE_INDEX[iSprite] = engfunc( EngFunc_PrecacheModel, gSprites[iSprite] );
		return ( g_bFoundSprite[iSprite] = true );
	}
	return false;
 }
 PM_FUNC_NORM_ATTRIB PokeModPrecacheSound( const POKE_SOUNDS:iSound )
 {
	new String:szSound[128];
	formatex( szSound, charsmax(szSound), "%s%s", gSoundDirectory, gSounds[iSound] );
	if ( file_exists( szSound ) || contain( gSounds[iSound], "pokemon" ) == -1 )
	{
		engfunc( EngFunc_PrecacheSound, gSounds[iSound] );
		return ( g_bFoundSound[iSound] = true );
	}
	return false;
 }
 PM_FUNC_NORM_ATTRIB PokeModMissingFiles()
 {
	pokemod_funcstart_debug( "PokeModMissingFiles" );

	new String:szFileNotFound[] = "Could not find file: %s";
	new Int:iFilesMissing;
	for ( new POKE_SOUNDS:iSound, String:szSound[128]; iSound < POKE_SOUNDS; iSound++ )
	{
		if ( !g_bFoundSound[ iSound ] )
		{
			formatex( szSound, charsmax(szSound), "%s%s", gSoundDirectory, gSounds[iSound] );
			log_amx( szFileNotFound, szSound );
			iFilesMissing++;
		}
	}
	for ( new POKE_SPRITES:iSprite; iSprite < POKE_SPRITES; iSprite++ )
	{
		if ( !g_bFoundSprite[ iSprite ] )
		{
			log_amx( szFileNotFound, gSprites[iSprite] );
			iFilesMissing++;
		}
	}
	for ( new POKE_MODELS:iModel; iModel < POKE_MODELS; iModel++ )
	{
		if ( !g_bFoundModel[ iModel ] )
		{
			log_amx( szFileNotFound, gModels[iModel] );
			iFilesMissing++;
		}
	}
	for ( new POKE_MODELST:iModelT; iModelT < POKE_MODELST; iModelT++ )
	{
		if ( !g_bFoundModelT[ iModelT ] )
		{
			log_amx( szFileNotFound, gModelsT[iModelT] );
			iFilesMissing++;
		}
	}

	pokemod_funcend_debug( "PokeModMissingFiles %d", iFilesMissing );

	return iFilesMissing;
 }

 #if defined POKEMOD_ADV_DEBUG
 PM_FUNC_PUBLIC_ATTRIB plugin_end()
 {
	pokemod_advdebug_end();
 }
 #endif
 
 
